<?php require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('weblink'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>导入表格</title>
<link href="templates/style/admin.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="templates/js/jquery.min.js"></script>
<script type="text/javascript" src="templates/js/getuploadify.js"></script>
<script type="text/javascript" src="templates/js/checkf.func.js"></script>
<script type="text/javascript" src="plugin/calendar/calendar.js"></script>
</head>
<body>
<div class="formHeader"> <span class="title">导入商品</span> <a href="javascript:location.reload();" class="reload">刷新</a> </div>
    <form name="form" id="form" method="post">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="formTable">
            <tr>
                <td height="40" align="right">商户：</td>
                <td><select id="uid" name="uid"  onchange="setMenchant(this.value);">
                    <option value="">选择商户</option>
                    <?php
                        $dosql->Execute("select * from dyspw_member where is_vip = 3");
                        while($merchant = $dosql->GetArray()){
                    ?>
                        <option value="<?php echo $merchant['id']; ?>" > <?php echo $merchant['username'];  ?> </option>
                    <?php } ?>
                </select><span class="maroon">*</span></td>
            </tr>

            <tr class="hideTr" style="display: none">
                <td height="40" align="right">类别：</td>
                <td><select id="tid" name="tid" >
                    </select><span class="maroon">*</span></td>
            </tr>


            <tr>
                <td height="40" align="right">上传表格：</td>
                <td><input type="file" name="file" id="file" class="input" /><span class="maroon">*</span>
                    </td>
            </tr>
        </table>
        <div class="formSubBtn">
            <input type="submit" class="submit" id="submit" value="提交" />
            <input type="button" class="back" value="返回" onclick="history.go(-1);" />
            <input type="hidden" name="action" id="action" value="add" />
        </div>
    </form>
    
    <div class="formHeader"> <span class="title">特约商户绑定导入</span></div>
    <form name="form" id="form" method="post">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="formTable">
            <tr>
                <td height="40" align="right">上传表格：</td>
                <td><input type="file" name="file" id="file" class="input" /><span class="maroon">*</span>
                    </td>
            </tr>
        </table>
        <div class="formSubBtn">
            <input type="submit" class="submit" id="submit_shop" value="提交" />
            <input type="button" class="back" value="返回" onclick="history.go(-1);" />
            <input type="hidden" name="action" id="action" value="add" />
        </div>
    </form>
</body>
<script>

function setMenchant(val){
    $.ajax({
        url : "/api/order.php?action=merchantType",
        type:'post',
        data:{'id':val},
        dataType:'json',
        success:function(res){
            if(!res.code){
                if(res.data.length){
                    $(".hideTr").show();
                    $.each(res.data,function(index,val){
                        $("#tid").append('<option value="'+val.id+'" > '+val.classname+' </option>');
                    });
                }
            }else {
                alert(res.message);
            }
        }
    });
}

$('#submit').click(function () {
    var uid = $('#uid').val();
    var tid = $('#tid').val();
    var formData = new FormData();
    formData.append("file",$('#file')[0].files[0]);
    formData.append("uid", uid);
    formData.append("tid", tid);
    $.ajax({
        url:'https://5p8.fyh5p8.com/xiaochengxu/excelUpload.php',
        dataType:'json',
        type:'POST',
        async: false,
        data: formData,
        processData : false, // 使数据不做处理
        contentType : false, // 不要设置Content-Type请求头
        success: function(data){
            console.log(data);
            if (data.status == '200') {
                alert('导入成功！');
            }

        },
        error:function(response){
            alert('导入失败！');
            console.log(response);
        }
    });

})

$('#submit_shop').click(function () {
    var formData = new FormData();
    formData.append("file",$('#file')[0].files[0]);
    $.ajax({
        url:'https://5p8.fyh5p8.com/xiaochengxu/shopexcelUpload.php',
        dataType:'json',
        type:'POST',
        async: false,
        data: formData,
        processData : false, // 使数据不做处理
        contentType : false, // 不要设置Content-Type请求头
        success: function(data){
            console.log(data);
            if (data.status == '200') {
                alert('导入成功！');
            }
        },
        error:function(response){
            alert('导入失败！');
            console.log(response);
        }
    });

})
</script>
</html>